package com.sm.filemanagelibrary.adapter;

import androidx.annotation.Nullable;

import com.scorpio.baselibrary.adapter.BasicQuickAdapter;
import com.scorpio.baselibrary.adapter.BasicViewHolder;
import com.scorpio.baselibrary.utils.FileSizeUtil;
import com.scorpio.baselibrary.utils.TimeUtil;
import com.sm.filemanagelibrary.model.FileEntity;
import com.sm.filemanagelibrary.util.FileLoadingUtil;
import com.sm.filemanagelibrary.R;

import java.util.List;

/**
 * created by zhud on 2019/9/26
 */
public class FileManageAdapter extends BasicQuickAdapter<FileEntity, BasicViewHolder> {

    public FileManageAdapter(@Nullable List<FileEntity> data) {
        super(R.layout.item_file_manage_layout, data);
    }

    @Override
    protected void convert(BasicViewHolder helper, FileEntity item) {
        helper.setText(R.id.file_text, item.name)
                .setGone(R.id.icon_rigth_image, item.isDirectory)
                .setText(R.id.file_time, TimeUtil.formatMsecConvertTime(TimeUtil.TIME_PATTERN_FULL, item.lastModified))
                .addOnClickListener(R.id.file_manage_item_layout);
        if (item.isDirectory) {
            helper.setImageResource(R.id.file_image, R.drawable.icon_file_folder)
                    .setText(R.id.file_size, item.size + getString(R.string.file_string_00002));
        } else {
            helper.setText(R.id.file_size, FileSizeUtil.FormetFileSize(item.size));
            helper.setImageResource(R.id.file_image, FileLoadingUtil.getFileImageRes(item.getType()));
        }

    }
}
